﻿
using Microsoft.AspNetCore.SignalR;
using System.Text.RegularExpressions;

namespace WebChat_MVC.Hubs
{
    public class ChatHub:Hub
    {
        public static UserContext db = new();

        public async Task Hello()
        {
            await Clients.All.SendAsync("hello","123");
        }

        public override Task OnConnectedAsync()
        {
            var user = db.Users.SingleOrDefault(x => x.UserName == Context.ConnectionId);
            if (user == null)
            {
                user = new User()
                {
                    UserName = Context.ConnectionId,
                };
                db.Users.Add(user);
            }

            return base.OnConnectedAsync();
        }
    }
}
